package com.my.test.thread.concurrent;

import java.util.concurrent.CountDownLatch;

public class TestCountDownLatch {

    private static int count = 0;

    private static CountDownLatch cdl = new CountDownLatch(10000);

    /**
     * 允许一个或多个线程等待其它线程完成操作
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    cdl.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("1111");
            }
        }).start();

        for (int i = 0; i <10000; i++) {
            new Thread (()->{
                ++count;
                cdl.countDown();

            }).start();
        }




        cdl.await();

        System.out.println(count);

    }





}
